<template>
  <div class="madp-picture-list">
    <mescroll-view class="scroll-view" :showMoreBtn="showMoreBtn" @getMoreData="getMoreData">
      <!-- 活动 -->
      <template v-if="type == 2">
        <div class="list1">
          <div class="item cursor-pointer" v-for="(item, idx) in list" :key="idx" @click="mxHandleClick(item)">
            <img :src="item.image1" />
          </div>
        </div>
      </template>
      <!-- 贷款 -->
      <template v-if="type == 4">
        <div class="list2">
          <div class="item cursor-pointer" v-for="(item, idx) in list" :key="idx" @click="mxHandleClick(item)">
            <img :src="item.image1" />
          </div>
        </div>
      </template>
      <!-- 信用卡 -->
      <template v-if="type == 5">
        <div class="list3">
          <div class="item cursor-pointer" v-for="(item, idx) in list" :key="idx" @click="mxHandleClick(item)">
            <img :src="item.image1" />
            <div class="name text-one-ellipsis">{{ item.name }}</div>
          </div>
        </div>
      </template>
    </mescroll-view>
    <back-btn />
  </div>
</template>
<script>
import MescrollView from '@/components/material/mescroll-view.vue'
import financialApi from '@/api/financial-shop.js'
import mxProductImage from '@/mixin/mxProductImage.js'
import mxInitWxConfig from '@/mixin/mxInitWxConfig.js'
import backBtn from '@/components/back-btn.vue'
export default {
  name: 'madp-picture-list',
  mixins: [mxProductImage, mxInitWxConfig],
  components: { MescrollView, backBtn },
  data() {
    return {
      wxUserId: '',
      showMoreBtn: false,
      type: 2,
      list: [],
      page: {
        current: 1,
        size: 20,
        total: 0
      }
    }
  },
  created() {},
  activated() {
    this.wxUserId = this.$route.query.wxUserId
    this.type = this.$route.query.type
    if (this.type == 2) {
      document.title = '活动'
    } else if (this.type == 4) {
      document.title = '贷款产品'
    } else if (this.type == 5) {
      document.title = '信用卡'
    }
    this.getProductList()
  },
  methods: {
    getMoreData() {
      this.page.current++
      this.getProductList()
    },
    getProductList() {
      this.list = []
      financialApi
        .getOtherProductList({
          current: this.page.current,
          size: this.page.size,
          type: this.type,
          wxUserId: this.wxUserId
        })
        .then((res) => {
          this.list = res.data.data.records
          this.page.total = res.data.data.total
          if (this.page.total > this.page.current * this.page.size) {
            this.showMoreBtn = true
          }
        })
    }
  }
}
</script>
<style scoped lang='scss'>
.madp-picture-list {
  width: 100%;
  min-height: 100vh;
  padding: 18px;
  background-color: #f9f9f9;
  .scroll-view {
    width: 100%;
    height: 100%;
    .list1 {
      display: flex;
      flex-direction: column;
      align-items: center;
      .item {
        background: #ffffff;
        box-shadow: 0px 3px 6px 0px rgba(181, 181, 181, 0.16);
        border-radius: 8px;
        width: 100%;
        margin-bottom: 20px;
        img {
          width: 100%;
        }
      }
    }
    .list2 {
      display: flex;
      flex-wrap: wrap;
      .item {
        background: #ffffff;
        box-shadow: 0px 3px 6px 0px rgba(181, 181, 181, 0.16);
        border-radius: 8px;
        width: 140px;
        margin: 10px;
        img {
          width: 100%;
        }
      }
    }
    .list3 {
      display: flex;
      flex-wrap: wrap;
      .item {
        width: 100%;
        margin-bottom: 10px;
        margin-right: 5px;
        background: #ffffff;
        box-shadow: 0px 3px 6px 0px rgba(181, 181, 181, 0.16);
        border-radius: 8px;
        img {
          width: 100%;
        }
        .name {
          font-size: 14px;
          font-family: PingFangSC-Medium, PingFang SC;
          font-weight: 500;
          color: #2c2c2c;
          margin-bottom: 6px;
          margin-left: 10px;
          margin-top: 3px;
        }
      }
    }
  }
}
</style>
